
//////////////////////////////////////////////////
////                                            //
//// Debug-Console                              //
////                                            //
////////////////////////////////////////////////// 

if (typeof window.medbiq === 'undefined') window.medbiq = {};
if (typeof window.medbiq.mvp === 'undefined') window.medbiq.mvp = {};
window.medbiq.mvp.logConsole = (function () {

 var initCSS = function () {
  var headID = document.getElementsByTagName ("head")[0];         
  var cssNode = document.createElement ('style');
  cssNode.type = 'text/css'; 
  var css = [
   'div.x-mvp-logConsole {',
    'font-family:sans-serif;',
    'font-size: 12px;',
    'width: 400px;',
    'height:150px;',
    'position: absolute;',
    'left: 0px;',
    'top: 0px;',
    'z-index: 3000;',
    '}',
   'div.x-mvp-logConsole-title {',
    'font-weight: bold;',
    'width: 100%;',
    'height: 16px;',
    'text-align: center;',
    'vertical-align: middle;',
    'background-color: #606060;',
    'border: 2px solid #606060;',
    'color: #ffffff;',
   '}',
   'div.x-mvp-logConsole-content {',
    'width: 100%;',
    'height: 100%;',
    'overflow: auto;',
    'background-color: #A0A0A0;',
    'font-family: mono-spaced;',
    'white-space: pre;',
    'border: 2px solid #606060;',
   '}',
   'div.x-mvp-logConsole-buttons {',
    'width: 100%;',
    'background-color: #606060;',
    'height: 28px;',
    'text-align:center;',
    'border: 2px solid #606060;',
   '}',
   'div.x-mvp-logConsole-buttons button {',
    'background-color:white;',
    'color:black',
    'height: 16px !important;',
    'margin:auto',
  '}',
   '.dynDiv_resizeDiv_br {',
    'position: absolute;',
    'bottom: -54px;',
    'right: -4px;',
    'width: 10px;',
    'height: 10px;',
    'background-color:#222222;',
    'z-index: 3001;',
    '}',
   '.x-mvp-logConsole-ns, .x-mvp-logConsole-data {',
    'cursor:pointer;',
    'font-weight:bold;',
    '}',
   '.x-mvp-logConsole-specEventName {',
    'font-style:italic;',
    '}'
    ].join ('');
  if (cssNode.styleSheet) {// IE
     cssNode.styleSheet.cssText = css;
     } else {
            var newStyle = document.createTextNode (css); 
            cssNode.appendChild (newStyle);
            }
  headID.appendChild (cssNode);
  initCSS = function () {};
  };

 var contentDIV = null;
 var text = [];

 var log = function (msg) {
  initCSS ();
  var e = document.createElement ('div');
  e.className = 'x-mvp-logConsole';
  var cornerDIV = document.createElement ('div');
  cornerDIV.className = 'dynDiv_resizeDiv_br';
  e.appendChild (cornerDIV);

  var titleDIV = document.createElement ('div');
  titleDIV.className = 'dynDiv_moveParentDiv x-mvp-logConsole-title';
  titleDIV.innerHTML = 'MVP-Log-Console';
  e.appendChild (titleDIV);
  contentDIV = document.createElement ('div');
  contentDIV.className = 'x-mvp-logConsole-content';
  e.appendChild (contentDIV);
  var buttonDIV = document.createElement ('div');
  buttonDIV.className = 'x-mvp-logConsole-buttons';
  buttonDIV.innerHTML = '<button onclick="medbiq.mvp.logConsole.clear()">Clear</button>';
  e.appendChild (buttonDIV);
  document.body.appendChild (e);

  ByRei_dynDiv.init.main ();

   
  log = function (msg) {
   text.push ('\n');
   text.push (msg);
   contentDIV.innerHTML = text.join ('');
   contentDIV.scrollTop = contentDIV.scrollHeight;
   };
  log (msg); 
  };


 // Add as implementation
 window.medbiq.mvp.log.registerImplementation ({
  eventReceived: function (e) {
   var h = [];
   h.push ('<span class="x-mvp-logConsole-ns" title="Namespace: ');
   h.push (e.ns);
   h.push ('" onclick="this.innerHTML=\'');
   h.push (e.ns);
   h.push ('\'">[NS]</span>&nbsp;');
   var specEventName = window.medbiq.mvp.log.getTypeName (e.ns, e.typeID);
   if (specEventName) {
      h.push ('<span class="x-mvp-logConsole-specEventName">');
      h.push (specEventName);
      h.push ('</span>&nbsp;');
      }       
   h.push ('<span title="Element-ID: ');
   h.push (e.elementID);
   h.push ('">');
   h.push (e.elementID);
   h.push ('</span>');
   if (e.data) {
      h.push ('&nbsp;<span class="x-mvp-logConsole-data" title="');
      h.push (e.data);
      h.push ('" onclick="this.innerHTML=\'');
      h.push (e.data);
      h.push ('\'">[DATA]</span>');
      }
   log (h.join (''));
   },
  isNamespaceSupported: function () { return true; }
  });

 return {
  clear: function () {
   contentDIV.innerHTML = '';
   text = [];
   }
  };
 }) ();